<?php
class PublicAction extends Action {

    public function display($templateFile=ACTION_NAME,$charset='',$contentType='text/html',$varPrefix=''){
        parent::display('Admin@Public:'.$templateFile);
    }

    public function login(){
        if(true===array_key_exists(C('USER_AUTH_KEY'), $_SESSION)) {
             $this->redirect('index','pAdmin');
        }else{
            $this->display();
        }
    }

    public function logout(){
        if(true===array_key_exists(C('USER_AUTH_KEY'), $_SESSION)) {
            session_destroy();
            $this->assign('msg',L('EXIT_SUCCESS'));
        }
        $this->display('login');
    }

    public function checkLogin(){
        $userDao=new UserModel();
        if(false===$userDao->doLogin()){
            $this->assign('msg',$userDao->getError());
            $this->display('login');
        }else{
            if(array_key_exists('remind', $_POST)){
                setcookie('account', trim($_POST['account']), time()+1209600);//两周内有效
            }
            $this->redirect('index', 'pAdmin');
        }
    }

    public function popedom(){
        if(array_key_exists(C('USER_AUTH_KEY'), $_SESSION)){
            $this->display('popedom');
        }else{
            $this->display('login');
        }
    }
}
